// Tags:
#include <algorithm>
#include <cstdio>

typedef long long ll;
const int N = 5e5 + 5;

struct Line {
  int a, b;
  inline bool operator<(const Line &rhs) const {
    return a == rhs.a ? b > rhs.b : a > rhs.a;
  }
} l[N];

int n, q, k;
ll suma[N], sumb[N];

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("games.in", "r", stdin);
  freopen("games.out", "w", stdout);
#endif
#endif

  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) { scanf("%d%d", &l[i].a, &l[i].b); }
  std::sort(l + 1, l + n + 1);
  for (int i = 1; i <= n; ++i) {
    suma[i] = suma[i - 1] + l[i].a;
    sumb[i] = sumb[i - 1] + l[i].b;
  }
  scanf("%d", &q);
  for (int m; q; --q) {
    scanf("%d%d", &k, &m);
    printf("%lld\n", suma[m] * k + sumb[m]);
  }
  return 0;
}